<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //函数封装反转数组
        function shuz(arr) {
            var arrs = []
            for (var i = arr.length - 1; i >= 0; i--) {
                arrs[arrs.length] = arr[i];
            }
            return arrs;
        }
        var nb = shuz([1, 2, 3, 4, 5, 6, 7]);
        console.log(nb);
console.log('----------------');
        //反转数组升级版
        function shuz(arr) {
          if(arr instanceof Array){//判断用户输入的是否是数组
            var arrs = []
            for (var i = arr.length - 1; i >= 0; i--) {
                arrs[arrs.length] = arr[i];
            }
          }else{
                return 'err:xxxx'
            }
            return arrs;
        }
        var dd=shuz(1,2,3,4);
        console.log(dd);
        var nb = shuz([1, 2, 3, 4, 5, 6, 7]);
        console.log(nb);

console.log('------------------');





        //;冒泡排序函数封装
        function arr(arrs) {
            for (var i = 0; i <= arrs.length - 1; i++) {
                for (var j = 0; j <= arrs.length - i - 1; j++) {
                    if (arrs[j] > arrs[j + 1]) {
                        temp = arrs[j];
                        arrs[j] = arrs[j + 1]
                        arrs[j + 1] = temp
                    }
                }
            }
            return arrs;
        }
        var hh = arr([7, 4, 6, 3, 2, 9, 1, 8, 5])
        console.log(hh);
    </script>
</body>

</html>